/*
 * CRtmpMediaCaster.h
 *
 *  Created on: 2016年9月15日
 *      Author: zhengboyuan
 */

#ifndef CRTMPMEDIACASTER_H_
#define CRTMPMEDIACASTER_H_

#include "RtmpMediaCaster.h"
#include "RtmpMediaSink.h"
#include "PacketDumper.h"
#include "TByteBuffer.h"


#ifdef WIN32
typedef int pthread_t;
#endif 


namespace av
{

class CRtmpMediaCaster: public RtmpMediaCaster, public RtmpMediaSink::EventSink
{
public:
	CRtmpMediaCaster();
	virtual ~CRtmpMediaCaster();

	virtual int open(const MediaFormat& fmt, const std::string& url);

	virtual void close();

	virtual bool isOpen();

	virtual void write(MediaPacketPtr& pkt);

	virtual void setCallback(CasterEventCallback cb, void* context);

	virtual void setID(caster_t id);

	virtual caster_t getID();


	virtual void onEvent(int type, const std::string& value);

protected:
	bool parseParamSet(MediaPacket& pkt);
	void parseH264Nalu(const uint8_t* data, size_t length);

	bool checkFormatReady();

	bool filter(MediaPacketPtr& pkt);

protected:
	RtmpMediaSink	m_sink;
	std::string m_sps;
	std::string m_pps;

	MediaFormat	m_format;
	std::string	m_url;

	caster_t	m_id;
	CasterEventCallback	m_eventCallback;
	void*	m_eventContext;

	comn::CriticalSection	m_cs;
	
	comn::ByteBuffer m_paramBuffer;
	

};

} /* namespace av */

#endif /* CRTMPMEDIACASTER_H_ */
